#include "collisions.h"

int collision_background_down(Samurai* player,BITMAP* picture)
{
int hauteur=0;
int largeur=0;
if (player->direction==1)
{
	hauteur = player->img_left[player->currentLeftFrame]->h;
	largeur = player->img_left[player->currentLeftFrame]->w;
}
else
{
	hauteur = player->img_right[player->currentRightFrame]->h;
	largeur = player->img_right[player->currentRightFrame]->w;
}
int pixelOK=0;
int i;
for(i=0;i<=largeur;i++)
{
if(getpixel(picture,player->xposition+i,player->yposition+hauteur+5)==makecol(255,255,255))
pixelOK++;
if (getpixel(picture,player->xposition+i,player->yposition+hauteur+5)==makecol(255,0,0))
return -1;
if (getpixel(picture,player->xposition+i,player->yposition+hauteur+5)==-1)
return -1;
if (getpixel(picture,player->xposition+i,player->yposition+hauteur+5)==makecol(0,0,255))
return 1000;
}
if (((float)pixelOK/largeur)> 0.4)
return 1;
return 0;
}


int collision_background_right(Samurai* player,BITMAP* picture)
{
	int hauteur=0;
	int largeur=0;
	if (player->direction==1)
	{
		hauteur = player->img_left[player->currentLeftFrame]->h;
		largeur = player->img_left[player->currentLeftFrame]->w;
	}
	else
	{
		hauteur = player->img_right[player->currentRightFrame]->h;
		largeur = player->img_right[player->currentRightFrame]->w;
	}
	int pixelOK=0;

	int i;
	for(i=0;i<=hauteur;i++)
	{
		if(getpixel(picture,player->xposition+largeur,player->yposition+i)==makecol(255,255,255))
		pixelOK++;
		if(getpixel(picture,player->xposition+largeur,player->yposition+i)==makecol(0,0,255))
		return 1000;
	}
	
	if ( (((float)pixelOK)/hauteur)>0.25 )
	return 1;	
	return 0;
}

int collision_background_left(Samurai* player,BITMAP* picture)
{
	int hauteur=0;

	if (player->direction==1)
	{
		hauteur = player->img_left[player->currentLeftFrame]->h;
	}
	else
	{
		hauteur = player->img_right[player->currentRightFrame]->h;
	}

	int pixelOK=0;

	int i;
	for(i=0;i<=hauteur;i++)
	{
		if(getpixel(picture,player->xposition,player->yposition+i)==makecol(255,255,255))
		pixelOK++;
		if(getpixel(picture,player->xposition,player->yposition+i)==makecol(0,0,255))
		return 1000;
	}
	
	if ( (((float)pixelOK)/hauteur)>0.25 )
	return 1;	
	return 0;
}

int collision_background_up(Samurai* player,BITMAP* picture)
{
	int hauteur=0;
	int largeur=0;
	if (player->direction==1)
	{
		hauteur = player->img_left[player->currentLeftFrame]->h;
		largeur = player->img_left[player->currentLeftFrame]->w;
	}
	else
	{
		hauteur = player->img_right[player->currentRightFrame]->h;
		largeur = player->img_right[player->currentRightFrame]->w;
	}
	int pixelOK=0;
	int i;
	for(i=0;i<=largeur;i++)
	{
		if(getpixel(picture,player->xposition+i,player->yposition)==makecol(255,255,255))
		pixelOK++;
		if(getpixel(picture,player->xposition+i,player->yposition)==makecol(0,0,255))
		return 1000;
	}
	if (((float)pixelOK/largeur)> 0.6)
	return 1;
	return 0;
}


